<template>
  <!--项目计划信息  -->
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="2"
      formType="show"
      :labelWidth="240"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getByPlanId } from '@/api/cms-api/projectOperating/program/oemInquire/index';
export default {
  mixins: [dictionary],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {},
      planId: ''
    };
  },
  mounted() {
    console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
    },
    async init() {
      if (this.value.type === 'edit') {
        this.planId = this.value.row.planId; //项目计划总结ID
        let res = {};
        res = await getByPlanId(this.planId);
        let resLogFinal = '';
        for (let i = 0; i < res.data.length; i++) {
          resLogFinal = res.data[res.data.length - 1];
        }
        this.initForm.forEach(x => {
          x.initialValue = resLogFinal[x.fieldName];
          if (x.fieldName == 'realApproveAmount') {
            if (x.initialValue == null) {
              x.initialValue = 0;
            }
          }
        });
        // this.initForm[5].initialValue = this.value.row.dealerSelfEvalution;
      }
    },
    //搜索数据
    initFormFun() {
      return [
        {
          type: 'TEXT_AREA',
          label: '事业部到场人数',
          fieldName: 'businessPeopleNum',
          initialValue: '',
          selfCols: 2,
          placeholder: ''
        },
        {
          type: 'INPUT',
          label: '实际批准金额',
          fieldName: 'realApproveAmount',
          initialValue: '',
          placeholder: '',
          selfCols: 2,
          numberFormat: true
          // rules: [{ required: true, message: '请输入实际批准金额', trigger: 'blur' }]
        },
        {
          type: 'RADIO',
          label: '场地（面积、规格）是否满足项目要求',
          fieldName: 'isSiteClaim',
          initialValue: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'RADIO',
          label: '营销素材是否按时准备到位',
          fieldName: 'isMaterialsClaim',
          initialValue: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'RADIO',
          label: '整体搭建效果是否与方案一致',
          fieldName: 'isProgramConsistent',
          initialValue: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'RADIO',
          label: '项目流程是否按计划执行',
          fieldName: 'isPlanGoon',
          initialValue: '',
          itemList: this.createDictList('1004')
        },
        {
          type: 'TEXT_AREA',
          label: '事业部评价',
          fieldName: 'overruleReason',
          initialValue: '',
          rows: 6,
          selfCols: 2,
          placeholder: '由事业部区域经理作评价，若评估为“中或差”，须填写原因及建议；评价内容包括但不限于“培训、项目营销素材、项目流程、项目整体效果等'
          // rules: [{ required: true, message: '请输入事业部评价', trigger: 'blur' }]
        }
      ];
    },
    formChangeHandle(val) {
      this.formValue = val;
      this.$emit('formchange', this.formValue);
    }
  },
  created() {
    this.init();
  }
};
</script>
